
const path = require("path")
const sql = require("../module")
const index = {
}
//  views 页面
index.views = (req, res) => {
    res.sendFile(path.resolve(__dirname, "../views/index.html"))
}

index.getnovel = async (req, res) => {

    let str = 'SELECT   a.* ,b.`name` as classify  from novel as a LEFT  JOIN  novel_class as b on a.classify = b.id  WHERE a.isdelete = 0'
    let [data] = await sql.query(str)
    console.log(data);
    res.json({
        code: 2000,
        data: data
    })
}

index.change = async (req, res) => {
    let { id, online } = req.body
    let str = `UPDATE novel  set online = ${online} WHERE id = ${id} `
    await sql.query(str)
    res.json({
        code: 2000,
        message: "修改成功"
    })


}

index.delete = async function (req, res) {
    let { id, status = 1 } = req.body
    // status=1 没有接受到就默认 = 1 
    console.log("数据更改", status);
    let str = `UPDATE novel  set isdelete = ${status - 0} WHERE id = ${id} `
    await sql.query(str)
    res.json({
        code: 2000,
        message: "修改成功"
    })
}

module.exports = index